using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Career : EveProperty
    {
        private int raceId;
        private string careerName;
        private string description;
        private string shortDescription;
        private int graphicId;
        private int schoolId;

        private Race race;
        private School school;
        private Graphic graphic;

        private List<CareerSkill> skills;

        public Race Race
        {
            get
            {
                if (race == null)
                    race = new Race(db, raceId);
                return race;
            }
        }
        public string Name
        {
            get { return careerName; }
        }
        public string Description
        {
            get { return description; }
        }
        public string ShortDescription
        {
            get { return shortDescription; }
        }
        public Graphic Graphic
        {
            get
            {
                if (graphic == null)
                    graphic = new Graphic(db, graphicId);
                return graphic;
            }
        }
        public School School
        {
            get
            {
                if (school == null)
                    school = new School(db, schoolId);
                return school;
            }
        }
        public List<CareerSkill> Skills
        {
            get
            {
                if (skills == null)
                {
                    skills = new List<CareerSkill>();
                    string query = "SELECT * FROM chrCareerSkills WHERE careerID=" + Id;
                    foreach (DbDataRow row in db.ExecuteQuery(query))
                        skills.Add(new CareerSkill(row, this));
                }
                return skills;
            }
        }

        internal Career(DbDataRow dr)
            : base(dr.Database, EvePropertyType.Career, dr["careerID"])
        {
            Fill(dr);
        }
        internal Career(Database db, int id)
            : base(db, EvePropertyType.Career, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM chrCareers WHERE careerID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            raceId = dr["raceID"];
            careerName = dr["careerName"];
            description = dr["description"];
            shortDescription = dr["shortDescription"];
            graphicId = dr["graphicID"];
            schoolId = dr["schoolID"];
        }
    }
}
